package com.tnt.hpit.helper;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.tnt.hpit.entitys.Ball;
import com.tnt.hpit.shared.Constants;

public class BallController extends InputAdapter{
	private OrthographicCamera camera;
	private Ball ball;
	private ControllerInputMultiplexer controllerIM;
	private Vector3 v3ToaDoManHinh;
	public BallController(OrthographicCamera camera, ControllerInputMultiplexer controllerIM, Ball ball){
		this.camera = camera;
		this.controllerIM = controllerIM;
		this.ball = ball;
		v3ToaDoManHinh = new Vector3();
	}
	@Override
	public boolean touchDown(int x, int y, int pointer, int button) {
		v3ToaDoManHinh.set(x, y, 0);
		camera.unproject(v3ToaDoManHinh);
		if (( v3ToaDoManHinh.x > ball.getX() ) && (v3ToaDoManHinh.x < ball.getX() + ball.getwidth()))
			if ((v3ToaDoManHinh.y > ball.getY() ) &&  
					(v3ToaDoManHinh.y < ball.getY() + ball.getHeight())){
				Gdx.app.log("TNT", "Touch down ball");
				controllerIM.setOneInputProcessor(this);
			}
		Gdx.app.log("TNT", v3ToaDoManHinh.x + " " + ball.getX() + " " + v3ToaDoManHinh.y + " " + ball.getY());
		return false;
	}
	
	@Override
	public boolean touchDragged(int x, int y, int pointer) {
//		Gdx.app.log("TNT", "Touch drag ball");
		return false;
	}
	@Override
	public boolean touchUp(int x, int y, int pointer, int button) {
		controllerIM.resetAllInputProcessor();
		return false;
	}
}
